
let s='([{}])'
var isValid = function(s) {
    const LToR = {
        '(':')',
        '{':'}',
        '[':']'
    }
    const stack =[]
    for(let i=0; i<s.length; i++){
        if(s[i]=== '['||s[i]=== '('||s[i]=== '{'){
            stack.push(s[i])
        }
        else{
            if(!stack.length||LToR[stack.pop()]!=s[i]){
                return false
            }
        }
    }
    if(stack.length){
        return false
    }
    return true
};

console.log(isValid(s));
console.log(s);

